package com.example.home_stretch;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Javascript_android extends AppCompatActivity {
    @BindView(R.id.webview_one)
    WebView webviewOne;
    @BindView(R.id.tv_wz)
    TextView tvWz;
//    @BindView(R.id.bu)
//    Button bu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.javascript_android);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        WebSettings webSettings = webviewOne.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webviewOne.addJavascriptInterface(new JsText(), "TEXT");
        webviewOne.loadUrl("file:///android_asset/bbb.html");
    }

    @OnClick(R.id.tv_wz)
    public void onViewClicked() {
        startActivity(new Intent(Javascript_android.this, Android_js.class));

    }

//    @OnClick(R.id.bu)
//    public void onViewClicked2() {
//    }

    private class JsText {
        @JavascriptInterface
        public void Hello(String msg) {
            Toast.makeText(Javascript_android.this, msg, Toast.LENGTH_SHORT).show();
        }
    }
}
